#include <iostream>
#include <fstream>

using namespace std;
//functions
void encrypt(int a = 199);
void decrypt(int a = 199);

int main()
{
//Beginning of Main()
//variables
char ch;

menu:
//Menu
cout<<"Encryption Program\nInput or Output?";
cin>>ch;
cin.clear();
cin.ignore(200, '\n');
if ((ch == 'o') || (ch == 'O'))
{
//Encrypt Message
encrypt();
}
else if((ch == 'i') || (ch == 'I'))
{
//Decrypt Message
decrypt();
}
else
{
//Go back to the menu
goto menu;
}
system("pause");
return 0;
}
//End of Main()


//Function Definitions
void encrypt(int a)
{
//variables
int message[1000];
int msglength = 0;
int x = 0;
int y = 0;
int z = 0;
string str;
ofstream outData;

//Encode Key
cout<<"Give the encode key: ";
cin>>a;
cin.clear();
cin.ignore(200, '\n');
//Get input for the message
cout<<"Type in your message:\n";
getline(cin,str);
//encode the message
//Translate the letters into ACII numbers.
msglength = str.length();
while(x<msglength)
{
message[x] = static_cast<int>(str[x]) * a;
cout<<"message["<<x<<"]: "<<message[x]<<endl;
x++;
}
//Write the message to a text file.
outData.open("message.ben");
while(y<msglength)
{
outData<<message[y]<<" ";
y++;
}
//Close the file
outData.close();
}
//end of Encrypt()

void decrypt(int a)
{
//variables
int message[1000];
int x = 0;
int y = 0;
int z = 0;
string str;
ifstream inData;
ofstream outData;

//Decode Key
cout<<"Give the decode key: ";
cin>>a;
cin.clear();
cin.ignore(200, '\n');
//Open the message for translation
inData.open("message.ben");
//Turn the txt chars into integers
while(!inData.eof())
{
inData>>message[x];
x++;
}

//Turn the integers into chars
while(y<x-1)
{
str[y] = message[y] /a;
cout<<"message["<<y<<"]: "<<message[y]<<endl;
y++;
}
//Write the message to a text file.
outData.open("message.txt");
while(z<y)
{
outData<<str[z];
z++;
}
//Close File
outData.close();
}
//End of File
